﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Dnf.Tools.Sugar
{
    public static class SocialMediaHelpers
    {
        public static bool IsYouTubeLink(string text)
        {
            var loweredtext = text.ToLower();
            if (loweredtext.StartsWith("http://www.youtube.com/watch") ||
                loweredtext.StartsWith("www.youtube.com/watch") ||
                loweredtext.StartsWith("http://www.youtube.com/w/") ||
                loweredtext.StartsWith("www.youtube.com/w/"))
            {
                //VideoLinks.Add(text);
                return true;
            }
            return false;
        }
        public static bool IsVimeoLink(string text)
        {
            var loweredtext = text.ToLower();
            if (loweredtext.StartsWith("http://vimeo.com") ||
                loweredtext.StartsWith("vimeo.com") ||
                loweredtext.StartsWith("http://www.vimeo.com") ||
                loweredtext.StartsWith("www.vimeo.com"))
            {
                //VideoLinks.Add(text);
                return true;
            }
            return false;
        }

        public static string ParseTwitterUserNames(string text, string usernameLinkTemplate)
        {
            string _html;
            var UsernameExpression = new Regex(@"^(@[a-zA-Z_0-9]*)|(\s@[a-zA-Z_0-9]*)|(\s@[a-zA-Z_0-9]*)$",
                                               RegexOptions.Compiled | RegexOptions.IgnoreCase |
                                               RegexOptions.Singleline);
            _html = UsernameExpression.Replace(text,
                                               match =>
                                               string.Format(
                                                   usernameLinkTemplate,
                                                   match.ToString().Trim().Substring(1),
                                                   (match.ToString().StartsWith("@") ? "" : " ")));
            return _html;
        }

        public static string ParseTwitterSearchTerms(string _html, string hashLinkTemplate)
        {
            var SearchExpression = new Regex(@"^(#[a-zA-Z_0-9]*)|(\s#[a-zA-Z_0-9]*)|(\s#[a-zA-Z_0-9]*)$",
                                             RegexOptions.Compiled | RegexOptions.IgnoreCase |
                                             RegexOptions.Singleline);

            _html = SearchExpression.Replace(_html,
                                             match =>
                                             string.Format(hashLinkTemplate,
                                                           match.ToString().Trim().Substring(1),
                                                           (match.ToString().StartsWith("#") ? "" : " ")));
            return _html;
        }
    }
}
